import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import store from '../store/index.js'

Vue.use(VueRouter)

const routes = [{
		path: '/',
		name: 'Home',
		component: Home
	},
	{
		path: '/about',
		name: 'About',
		component: function() {
			return import('../views/About.vue')
		},
		children: [{
			path: '/houseing',
			name: 'Houseing',
			component: function() {
				return import('../views/Houseing.vue')
			}
		}, {
			path: '/live',
			name: 'Live',
			component: function() {
				return import('../views/Live.vue')
			}
		}, {
			path: '/groupbay',
			name: 'Groupbay',
			component: function() {
				return import('../views/Groupbay.vue')
			}
		}, {
			path: '/audit',
			name: 'Audit',
			component: function() {
				return import('../views/Audit.vue')
			}
		}, {
			path: '/order',
			name: 'Order',
			component: function() {
				return import('../views/Order.vue')
			}
		}, {
			path: '/consult',
			name: 'Consult',
			component: function() {
				return import('../views/Consult.vue')
			}
		}, {
			path: '/broker',
			name: 'Broker',
			component: function() {
				return import('../views/Broker.vue')
			}
		},{
			path: '/user',
			name: 'User',
			component: function() {
				return import('../views/User.vue')
			}
		},{
			path: '/feedback',
			name: 'Feedback',
			component: function() {
				return import('../views/Feedback.vue')
			}
		}]
	}
]

const router = new VueRouter({
	mode: 'history',
	base: process.env.BASE_URL,
	routes
})

router.beforeEach((to, from, next) => {
	if (to.path !== '/' && !store.state.admin.token) {
		alert('请登录')
		next('/')
	} else {
		next()
	}
})

export default router
